vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; }
int ans = 0; { priority_queue<int> pque; longlong sum = 0; for (int i = m - 1; i > 0; i--) { sum += a[i]; if (a[i] > 0) { pque.push(a[i]); } while (sum > 0) { int x = pque.top(); pque.pop(); sum -= 2 * x; ans += 1; } } } { priority_queue<int, vector<int>, greater<int>> pque; longlong sum = 0; for (int i = m; i < n; i++) { sum += a[i]; if (a[i] < 0) { pque.push(a[i]); } while (sum < 0) { int x = pque.top(); pque.pop(); sum -= 2 * x; ans += 1; } } } cout << ans << "\n"; }
#define ls (o<<1) #define rs ((o<<1)|1) #define mid ((l+r)>>1)
constint N = 2e5 + 100; int tree[4 * N];
voidbuild(int o, int l, int r, vector<int>& b){ if (l == r) { tree[o] = b[l - 1]; return; } build(ls, l, mid, b); build(rs, mid + 1, r, b); tree[o] = max(tree[ls], tree[rs]); }
intget(int o, int l, int r, int x){ if (l == r) return l; return tree[ls] > x ? get(ls, l, mid, x) : get(rs, mid+1, r, x); }
intquery(int o, int l, int r, int ql, int qr, int x){ //查询[ql, qr]内第一个大于 x 的数的位置 if (qr < l || r < ql) return-1; if (ql <= l && r <= qr) return tree[o] > x ? get(o, l, r, x) : -1; int t = query(ls, l, mid, ql, qr, x); return t != -1 ? t : query(rs, mid + 1, r, ql, qr, x); }
for (int i = 0; i < n; i++) { if (vis[i]) { continue; } if (a[i] != b[i]) { if (mst.find(b[i]) == mst.end()) { ok = false; break; } else { mst.erase(mst.find(b[i])); } int r = query(1, 1, n, i + 1, n, b[i]); r = (r == -1 ? n : r - 1); while (not mp[b[i]].empty() and mp[b[i]].front() < r) { vis[mp[b[i]].front()] = true; mp[b[i]].pop(); } } }